package cosplay.controller;

import java.sql.CallableStatement;
import java.sql.ResultSet;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

@Controller
public class Test extends AbstractController {
	@Autowired
	DataSource data;

	@Override
	@RequestMapping(value="test.htm")
	protected ModelAndView handleRequestInternal(HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		// TODO Auto-generated method stub
		String sql="CALL test(?);";
		CallableStatement stm =data.getConnection().prepareCall(sql);
		stm.registerOutParameter(1, java.sql.Types.INTEGER);
		ResultSet rs=stm.executeQuery();
		int count=stm.getInt(1);
		res.getOutputStream().println("count number:"+count+"");
		while (rs.next())
		{
			res.getOutputStream().println("description:"+rs.getString("description")+"id:"+rs.getInt("id")+"");
		}
		return null;
	}
}
